package com.daniel.controller;

import com.daniel.entity.UserRoleVO;
import com.daniel.service.impl.UserInfoService;
import com.daniel.utils.response.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 用户接口
 * @Author GanShaoXi
 * @ClassName UserController
 * @Return com.daniel.controller
 * @Since 1.0.0
 * @Created on 2023/5/21 17:44
 * @module java-260-springboot-redis-jedis
 */
@Slf4j
@RestController
@RequestMapping("user/")
public class UserController {


    @Autowired
    UserInfoService userInfoService;

    /**
     * 查询所有用户
     *
     * @return
     */
    @RequestMapping("list/")
    public ResponseResult findAllUser() {
        return ResponseResult.success(userInfoService.findUserRoleList());
    }

    /**
     * 查询所有用户通过某些条件
     *
     * @return
     */
    @RequestMapping("query/")
    public ResponseResult queryUser(
            @RequestParam(value = "userId", required = false, defaultValue = "") String userId,
            @RequestParam(value = "userName", required = false, defaultValue = "") String userName,
            @RequestParam(value = "age", required = false, defaultValue = "") Integer age,
            @RequestParam(value = "email", required = false, defaultValue = "") String email,
            @RequestParam(value = "gender", required = false, defaultValue = "") String gender,
            @RequestParam(value = "ethnicity", required = false, defaultValue = "") String ethnicity,
            @RequestParam(value = "jobTitle", required = false, defaultValue = "") String jobTitle,
            @RequestParam(value = "address", required = false, defaultValue = "") String address,
            @RequestParam(value = "createDate", required = false, defaultValue = "") String createDate,
            @RequestParam(value = "city", required = false, defaultValue = "") String city,
            @RequestParam(value = "roleName", required = false, defaultValue = "") String roleName,
            @RequestParam(value = "roleCode", required = false, defaultValue = "") Integer roleCode
    ) {
        return ResponseResult.success(userInfoService.queryUserRoleList(new UserRoleVO(userId, userName, age, email, gender, ethnicity, jobTitle, address, createDate, city, roleName, roleCode)));
    }
}
